import React from 'react';
import ReactDom from 'react-dom';
import axios from 'axios';
import Message from '../TinyComponents/Message';

//创建自定义配置的axios对象
export let cloudMusicAxios = axios.create({
      baseURL: 'http://140.82.6.157:3000',
      timeout: 800000,
      //跨域请求
      xhrFields: {
            withCredentials: true
      },
});

let ShowMessage = () => {
      ReactDom.render(
            <Message text="已登录网易云音乐用户 ‘一条受伤的海绵体’ 的账号,本站所有歌曲皆来自于网易云音乐"></Message>,
            document.getElementById('message')
      );
}

export async function loginCloudMusic() {
      //如果cookie有效，就调用登录接口，避免频繁调用
      if (!document.cookie) {
            cloudMusicAxios.get('/login/cellphone', {
                  params: {
                        phone: 18696486864,
                        password: 'qq123456',
                  }
            })
                  .then(function (response) {
                        console.log(response);
                        ShowMessage();
                  })
                  .catch(function (error) {
                        console.log(error);
                  });
      } else {
            ShowMessage();
      }
}
